package com.baohua.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.baohua.dao.BaseDao;
import com.baohua.dao.InStoreDao;
import com.baohua.model.InStore;
import com.baohua.model.Staff;

/**
 * 入库出库的接口实现类
 * @author czp
 *
 */
@Repository("instoreDao")
public class InStoreDaoImpl extends BaseDao implements  InStoreDao{

	/**
	 * 增加出库/入库数据
	 * @param instore
	 */
	public void addInStore(InStore instore){
		this.getSession().save(instore);
	}
	
	/**
	 * 删除出库/入库数据
	 * @param instore
	 */	
	public void deleteInStore(InStore instore){
		this.getSession().delete(instore);
	}
	

	/**
	 * 根据HQL语句查询相应的数据
	 * @param querySQL HQL语句
	 * @param page
	 * @param pagesize
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<InStore> queryInStore(String querySQL, int page, int pagesize){
		return this.getSession().createQuery(querySQL).setFirstResult(page)
				.setMaxResults(pagesize).list();
	}

	/**
	 * 根据ID查询数据
	 * @param id
	 * @return
	 */
	@Override
	public InStore queryInStoreById(int id) {
		return (InStore)this.getHibernateTemplate().load(InStore.class, id);
	}

	/**
	 * 统计出库/入库数据
	 * @param hql
	 * @return
	 */
	@Override
	public long countInStore(String hql) {
		long count = (Long)this.getSession().createQuery(hql).uniqueResult();
		return count;
	}

	@Override
	public List<InStore> queryByInstoreIds(Integer[] instoreIds) {
		String hql = "from InStore i where i.inStoreId in (:instoreIds)";
		List<InStore> list = this.getSession().createQuery(hql).setParameterList("instoreIds", instoreIds).list();
		return list;
	}

	
}
